<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/12/3
 * Time: 10:30 AM
 */

namespace App\Utils;

use Illuminate\Support\Facades\Redis;

/**
 * 退款订单号生成器
 * Class RefundNoGeneratorUtil
 * @package App\Utils
 */
class RefundNoGeneratorUtil
{
    /**
     * 退款订单号前缀
     */
    public const PREFIX = '500';

    public const REFUND_NO_IDENTIFY = 'REFUND_NO_IDENTIFY:';

    /**
     * @return string
     */
    public static function get(): string
    {
        $timestamp = time();
        $key = self::REFUND_NO_IDENTIFY . $timestamp;

        $nu = Redis::incr($key);
        Redis::expire($key, 5);

        return (string) self::PREFIX . Date('YmdHis', $timestamp) . $timestamp . sprintf('%06s', $nu);
    }
}
